package client;

import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;

import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;

/**
 * Player hand. Contains 4 cards.
 * 
 * @author papq
 */
public class HandPanel extends JPanel {
	private MainViewJFrame mainViewJFrame;
	private Model model;

	private JButton[] buttonCard = new JButton[4];
	int i;

	public HandPanel(final MainViewJFrame mainViewJFrame, final Model model) {
		super();
		this.mainViewJFrame = mainViewJFrame;
		this.model = model;

		setLayout(new FlowLayout());

		for (i = 0; i < 4; i++) {
			buttonCard[i] = new JButton();
			buttonCard[i].setPreferredSize(new Dimension(150, 200));
			buttonCard[i].setEnabled(false);
			add(buttonCard[i]);
		}

		buttonCard[0].addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				model.setPressedButton("CARD 0");
				mainViewJFrame.answearTextField
						.setText("You selected card no. " + (0 + 1) + ".");
				mainViewJFrame.setChanged();
				mainViewJFrame.notifyObservers();
			}
		});
		buttonCard[1].addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				model.setPressedButton("CARD 1");
				mainViewJFrame.answearTextField
						.setText("You selected card no. " + (1 + 1) + ".");
				mainViewJFrame.setChanged();
				mainViewJFrame.notifyObservers();
			}
		});
		buttonCard[2].addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				model.setPressedButton("CARD 2");
				mainViewJFrame.answearTextField
						.setText("You selected card no. " + (2 + 1) + ".");
				mainViewJFrame.setChanged();
				mainViewJFrame.notifyObservers();
			}
		});
		buttonCard[3].addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent arg0) {
				model.setPressedButton("CARD 3");
				mainViewJFrame.answearTextField
						.setText("You selected card no. " + (3 + 1) + ".");
				mainViewJFrame.setChanged();
				mainViewJFrame.notifyObservers();
			}
		});
	}

	/**
	 * Sets card symbol and color into first card button.
	 * 
	 * @param cardInText
	 *            card saved in a string, for e.g. "QUEEN of hearts"
	 */
	public void setButtonCard0Text(String cardInText) {
		this.buttonCard[0].setText(cardInText);
	}

	/**
	 * Sets card symbol and color into second card button.
	 * 
	 * @param cardInText
	 *            card saved in a string, for e.g. "QUEEN of hearts"
	 */
	public void setButtonCard1Text(String cardInText) {
		this.buttonCard[1].setText(cardInText);
	}

	/**
	 * Sets card symbol and color into third card button.
	 * 
	 * @param cardInText
	 *            card saved in a string, for e.g. "QUEEN of hearts"
	 */
	public void setButtonCard2Text(String cardInText) {
		this.buttonCard[2].setText(cardInText);
	}

	/**
	 * Sets card symbol and color into fourth card button.
	 * 
	 * @param cardInText
	 *            card saved in a string, for e.g. "QUEEN of hearts"
	 */
	public void setButtonCard3Text(String cardInText) {
		this.buttonCard[3].setText(cardInText);
	}

	/**
	 * Sets buttonCard0 disabled - cannot be clicked again.
	 */
	public void setButtonCard0Disabled() {
		this.buttonCard[0].setEnabled(false);
	}

	/**
	 * Sets buttonCard1 disabled - cannot be clicked again.
	 */
	public void setButtonCard1Disabled() {
		this.buttonCard[1].setEnabled(false);
	}

	/**
	 * Sets buttonCard2 disabled - cannot be clicked again.
	 * 
	 */
	public void setButtonCard2Disabled() {
		this.buttonCard[2].setEnabled(false);
	}

	/**
	 * Sets buttonCard3 disabled - cannot be clicked again.
	 */
	public void setButtonCard3Disabled() {
		this.buttonCard[3].setEnabled(false);
	}

	/**
	 * Sets all buttonCard[i] enabled - can be clicked.
	 */
	public void setAllButtonCardsEnabled() {
		this.buttonCard[0].setEnabled(true);
		this.buttonCard[1].setEnabled(true);
		this.buttonCard[2].setEnabled(true);
		this.buttonCard[3].setEnabled(true);
	}
}
